package at.codebase.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Daniel Marth <danielmarth@gmx.at>
 */
public class TokenPool implements Serializable {
	private static final long serialVersionUID = -5166307441180896397L;
	
	private List<String> tokens = new ArrayList<String>();

	private static int maxSize = Settings.XSRF_TOKEN_POOL_SIZE;

	public synchronized String generate() {
		if (tokens.size() > maxSize) {
			tokens.remove(0);
		}
		String t = StringTools.generateBase64RandomString();
		tokens.add(t);
		return t;
	}

	public synchronized boolean remove(String t) {
		return tokens.remove(t);
	}

}
